package main

import (
	"go-security/Security"
	"log"
)

func main() {
	log.SetFlags(log.LstdFlags | log.Lshortfile)
	log.Println("程序开始....")
	//key至少128位，可选192，256
	key := []byte("76543456*&^%$#@!")
	iv := []byte("34234323!@#$%^&*")
	data := "122.195.54.10:3306"
	//Aes加密 key不能小于16位，16,24,32位三种
	AesEnout, _ := Security.AesEncrypt(data, key, iv)
	log.Println("Aes加密后:", AesEnout)
	//Aes解密
	AesDeout, _ := Security.AesDecrypt(AesEnout, key, iv)
	log.Println("Aes解密后:", AesDeout)

	// key = []byte("76543456")
	// iv = []byte("34234323")
	key = []byte{54, 224, 97, 32, 70, 109, 204, 115}
	iv = []byte{21, 19, 57, 110, 105, 159, 77, 45}
	//Des加密
	DesEnout, _ := Security.DesEncrypt(data, key, iv)
	log.Println("Des加密后:", DesEnout)
	//Des解密
	DesDeout, _ := Security.DesDecrypt(DesEnout, key, iv)
	log.Println("Des解密后:", DesDeout)

	//RSA算法
	//
	//生成公钥和私钥文件
	//Security.GenRsaKey(1024)
	Security.LoadKeyFile() //载入密钥文件
	RsaEncryptData, _ := Security.RsaEncrypt([]byte("OrigText"))
	log.Println("RSA加密后：", RsaEncryptData)
	RsaDecryptData, _ := Security.RsaDecrypt(RsaEncryptData)
	log.Println("RSA解密后：", string(RsaDecryptData))
}
